Skip to content

Mark setindex! on SizedArray as possible#45

Merged
MasonProtter merged 1 commit intoJuliaFolds2:masterfrom
penelopeysm:master
Jan 25, 2026
Merged

Mark setindex! on SizedArray as possible#45
MasonProtter merged 1 commit intoJuliaFolds2:masterfrom
penelopeysm:master

Conversation

@penelopeysm
Copy link
Collaborator

@penelopeysm penelopeysm commented Jan 25, 2026

StaticArrays.SizedArray is mutable and has setindex! defined on it (method is defined here), so this PR allows BangBang to make use of it:

julia> using BangBang, StaticArrays

julia> v = @SVector zeros(3)
3-element SVector{3, Float64} with indices SOneTo(3):
 0.0
 0.0
 0.0

julia> v2 = similar(v, Real)
3-element SizedVector{3, Real, Vector{Real}} with indices SOneTo(3):
 #undef
 #undef
 #undef

julia> setindex!(v2, 1.0, 1)
3-element SizedVector{3, Real, Vector{Real}} with indices SOneTo(3):
   1.0
 #undef
 #undef

julia> # With this PR
       BangBang.setindex!!(v2, 1.0, 1)
3-element SizedVector{3, Real, Vector{Real}} with indices SOneTo(3):
   1.0
 #undef
 #undef

Right now BangBang.setindex!! errors as it tries to go through an immutable path, which hits JuliaArrays/StaticArrays.jl#1330:

julia> v3 = similar(v, Real)
3-element SizedVector{3, Real, Vector{Real}} with indices SOneTo(3):
 #undef
 #undef
 #undef

julia> BangBang.setindex!!(v3, 1.0, 1)
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex
   @ ./essentials.jl:917 [inlined]
 [2] getindex
   @ ~/.julia/packages/StaticArrays/IZgIP/src/SizedArray.jl:92 [inlined]
 [3] macro expansion
   @ ~/.julia/packages/StaticArrays/IZgIP/src/deque.jl:193 [inlined]
 [4] _setindex
   @ ~/.julia/packages/StaticArrays/IZgIP/src/deque.jl:186 [inlined]
 [5] setindex
   @ ~/.julia/packages/StaticArrays/IZgIP/src/deque.jl:185 [inlined]
 [6] _setindex
   @ ~/ppl/BangBang.jl/ext/BangBangStaticArraysExt.jl:27 [inlined]
 [7] may
   @ ~/ppl/BangBang.jl/src/core.jl:11 [inlined]
 [8] setindex!!(xs::SizedVector{3, Real, Vector{Real}}, v::Float64, I::Int64)
   @ BangBang ~/ppl/BangBang.jl/src/base.jl:478
 [9] top-level scope
   @ REPL[15]:1

@MasonProtter
Copy link
Member

Thank you!

@MasonProtter MasonProtter merged commit 9a255bd into JuliaFolds2:master Jan 25, 2026
13 checks passed
@penelopeysm
Copy link
Collaborator Author

Thanks @MasonProtter! I would ask you for a release; but maybe I can do one better.

Turing.jl currently already uses BangBang quite heavily and in the near future that reliance will only increase. Seven of the eight most recent open issues are from current or ex-Turing devs, and I ran into a few more problems getting it to work with DimensionalData which I haven't gotten around to reporting :-)

I am the only one left on the project now, but if you would like, I am happy to help maintain the repo and maybe even try to fix some of them. Obviously PRs will still need to be reviewed, but I can help with the grunt work of releases, CI, and stuff.

@MasonProtter
Copy link
Member

Yes, that would be great!

@penelopeysm
Copy link
Collaborator Author

Amazing, thank you! I shall try to register and hope the bot picks up collaborator status...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants